package com.clkj.zhonghui.controller.system;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.system.Affiche;
import com.clkj.zhonghui.pojo.system.Url;
import com.clkj.zhonghui.service.system.AfficheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 周佳润
 * @Date 2024/9/12 上午10:20
 */
@RestController
@RequestMapping(value = "/affiche")
@CrossOrigin
@Api(value = "/affiche", tags = {"公告管理"})
public class AfficheController {

    @Autowired
    private AfficheService afficheService;

    @ApiOperation(value = "添加公告")
    @PostMapping("/addUrl")
    public Result addAddress(Affiche affiche){
        try {
            afficheService.addAffiche(affiche);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }

    }

    @ApiOperation(value = "获取公告列表")
    @PostMapping("/listUrl")
    public Result listUrl(){
        try {
            List<Affiche> addrList  = afficheService.listAffiche();
            return new Result(true, StatusCode.OK,"查询成功",addrList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }

    }

    @ApiOperation(value = "删除公告")
    @PostMapping("/delUrl")
    public Result delUrl(@RequestParam("afficheId") Integer afficheId){
        try {
            afficheService.delAffiche(afficheId);
            return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"删除失败");
        }

    }
}
